<template>
  <view
    class="search-box flex items-center bg-white rounded-1 px-[24rpx] py-[20rpx]"
  >
    <wd-icon name="search" size="18" color="#86909C"></wd-icon>
    <view class="flex-1 mx-2 color-text-4" @click="handleToSearch">
      {{ placeholder }}
    </view>
    <wd-icon
      name="scan"
      size="20"
      color="#333"
      @click="handleScan"
      v-show="showScan"
    ></wd-icon>
  </view>
</template>

<script setup>
const handleToSearch = () => {
  uni.navigateTo({
    url: "/pages/search/index",
  });
};
const props = defineProps({
  showScan: {
    type: Boolean,
    default: true,
  },
  placeholder: {
    type: String,
    default: "按商品名称、编码、适配型号搜索",
  },
});
const handleScan = () => {
  uni.scanCode({
    success: (res) => {
      console.log("扫码结果：", res);
      // 这里可以处理扫码后的逻辑
    },
  });
};
</script>
